#ifndef XML_CONFIG_H
#define XML_CONFIG_H
#include "cdecl.h"
#include "trajectory.h"
#include "current.h"

/**
 * The module provides routines to read simulation data from xml file.
 */

struct discharge {
	union trajectory trj;
	union trajectory_len trlen; // To be constructed by trj, IT needs deallocating before throwing object away!
	struct current crnt;
	double t_start; // Start of discharge processes, (t_start > 0)
	struct discharge * next;
};
/**
 * Frees discharge object.
 * @param dis - object to free
 */
void discharge_free(struct discharge * dis);

/**
 * Performs z=0 mirror reflection of the discharge.
 * 
 * @param dis - discharge
 * @param refl - reflection
 * @return 0 - OK
 *         1 - Out of memory
 */ 
int discharge_mirror(const struct discharge * dis, struct discharge * refl);

struct configuration {
	// Source
	struct discharge * discharges; // Discharge Linked list root object
	boolean has_mirror; // Ideally conductive {z=0} surface
	
	// Observation parameters
	double r[3]; // Observer coordinates
	enum field_EH field_class; // E or H
	double n[3]; // Observation vector, not \mathbb(0), determiones which projection of field will be calculated
};

/**
 * Reads XML config from file_desc descriptor. Prints any parsing error
 * messages to stderr.
 * @param cfg - configuration structure to fill
 * @param file_desc - descriptor of a stream to take XML from 
 * @return 0 - success
 *         1 - xml parser failed
 *         2 - out of memory
 *         3 - wrong content (comment on stderr)
 */
int xml_config_parser(struct configuration * cfg, int file_desc);


/**
 * Releases data, allocated in configuration object.
 * @param cfg - object to free
 */
void configuration_free(struct configuration * cfg);

/**
 * For every element in given linked list of discharges, calls 
 * discharge_free and free()-s memory segment.
 * @param root - first element of the discharge linked list, NULL is OK
 */
void trash_discharge_list(struct discharge * root);


#endif
